home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / saveargs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  2.5 KB  |  119 lines

  1. /* @(#)saveargs.c    1.8 00/04/12 Copyright 1995 J. Schilling */
  2. /* save argc, argv for command error printing routines */
  3. /*
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2, or (at your option)
  7.  * any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; see the file COPYING.  If not, write to
  16.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  */
  18.  
  19. #include <mconfig.h>
  20. #include <standard.h>
  21. #include <strdefs.h>
  22. #include <stdxlib.h>
  23. #include <avoffset.h>
  24.  
  25. #if    !defined(AV_OFFSET) || !defined(FP_INDIR)
  26. #    ifdef    HAVE_SCANSTACK
  27. #    undef    HAVE_SCANSTACK
  28. #    endif
  29. #endif
  30. #ifdef    NO_SCANSTACK
  31. #    ifdef    HAVE_SCANSTACK
  32. #    undef    HAVE_SCANSTACK
  33. #    endif
  34. #endif
  35.  
  36. static    int    ac_saved;
  37. static    char    **av_saved;
  38. static    char    *av0_saved;
  39. static    char    *progname_saved;
  40.  
  41. static    char    av0_sp[32];    /* av0 space, avoid malloc() in most cases */
  42. static    char    prn_sp[32];    /* name space, avoid malloc() in most cases */
  43. static    char    dfl_str[] = "?";
  44.  
  45. void save_args(ac, av)
  46.     int    ac;
  47.     char    *av[];
  48. {
  49.     int    slen;
  50.  
  51.     ac_saved = ac;
  52.     av_saved = av;
  53.  
  54.     if (av0_saved && av0_saved != av0_sp)
  55.         free(av0_saved);
  56.  
  57.     slen = strlen(av[0]) + 1;
  58.  
  59.     if (slen <= (int)sizeof(av0_sp))
  60.         av0_saved = av0_sp;
  61.     else
  62.         av0_saved = malloc(slen);
  63.  
  64.     if (av0_saved)
  65.         strcpy(av0_saved, av[0]);
  66. }
  67.  
  68. int saved_ac()
  69. {
  70.     return (ac_saved);
  71. }
  72.  
  73. char **saved_av()
  74. {
  75.     return (av_saved);
  76. }
  77.  
  78. char *saved_av0()
  79. {
  80.     return (av0_saved);
  81. }
  82.  
  83. void set_progname(name)
  84.     const char    *name;
  85. {
  86.     int    slen;
  87.  
  88.     if (progname_saved && progname_saved != prn_sp)
  89.         free(progname_saved);
  90.  
  91.     slen = strlen(name) + 1;
  92.  
  93.     if (slen <= sizeof(prn_sp))
  94.         progname_saved = prn_sp;
  95.     else
  96.         progname_saved = malloc(slen);
  97.  
  98.     if (progname_saved)
  99.         strcpy(progname_saved, name);
  100. }
  101.  
  102. char *get_progname()
  103. {
  104. #ifdef    HAVE_SCANSTACK
  105.     char    *progname;
  106. #endif
  107.  
  108.     if (progname_saved)
  109.         return (progname_saved);
  110.     if (av0_saved)
  111.         return (av0_saved);
  112. #ifdef    HAVE_SCANSTACK
  113.     progname = getav0();        /* scan stack to get argv[0] */
  114.     if (progname)
  115.         return (progname);
  116. #endif
  117.     return (dfl_str);
  118. }
  119.